<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class Zhishidi_Newarrival_Block_List extends Mage_Catalog_Block_Product_List {
    const SIDEBAR_CACHE_KEY = 'zhishidi_newarrival_list';
    const XML_BEST_SELLERS_MODEL_PATH = 'zhishidi_newarrival/settings';
  
    protected $_columnCountLayoutDepend = array();
    protected function _construct() {
        parent::_construct();      
          $this->addData(array(
          'cache_lifetime' => 86400,
          'cache_tags' => array(self::SIDEBAR_CACHE_KEY),
          ));
       
    } 
    
    protected  function _beforeToHtml() {        
         $toolbar = $this->getToolbarBlock();
         $toolbar->setAvailableOrders(array('created_at' => $this->__('New Arrival')))
                 ->setDefaultOrder('created_at')
                 ->setDefaultDirection('desc');
        return parent::_beforeToHtml();
    }


    protected function _getProductCollection() {
        if (is_null($this->_productCollection)) {
            $collection = Mage::getResourceModel('catalog/product_collection');
            $collection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());
            $collection = $this->_addProductAttributesAndPrices($collection)
                            ->addStoreFilter()
                            ->setOrder('created_at', 'desc');
            $this->_productCollection = $collection;
        }
        return $this->_productCollection;
    }

    public function getLoadedProductCollection() {
        return $this->_getProductCollection();
    }

    protected function getModel() {
        return Mage::getModel(self::XML_BEST_SELLERS_MODEL_PATH);
    }

}

?>
